package com.dliu.javadesign.create.prototype;

/**
 * @author yanglei
 * date 2021/3/30 10:09
 */
public abstract class Animal implements Cloneable{

    private Integer id;
    protected String name;

    abstract void voice();

    public Integer getId() {
        return id;
    }

    public void setId(Integer id) {
        this.id = id;
    }

    public String getName() {
        return name;
    }

    public Animal clone(){
        Object clone = null;
        try {
            clone = super.clone();
        } catch (CloneNotSupportedException e) {
            e.printStackTrace();
        }
        return (Animal) clone;
    }
}

class Dog extends Animal{

    Dog(){
        name = "狗";
        setId(1);
    }

    @Override
    void voice() {
        System.out.println("我是"+name+" 叫声：汪汪汪~");
    }
}

class Cat extends Animal{
    Cat(){
        name = "猫";
        setId(2);
    }

    @Override
    void voice() {
        System.out.println("我是"+name+" 叫声：喵喵喵~");
    }
}
